package com.xfcy.blog.strategy.context;

import com.xfcy.blog.strategy.FileUploadStrategy;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 文件上传策略上下文
 *
 * @author 晓风残月Lx
 * @date 2023/5/4 15:41
 */
@Service
public class FileUploadStrategyContext {

    @Resource
    private Map<String, FileUploadStrategy> fileUploadStrategyMap = new ConcurrentHashMap<String, FileUploadStrategy>();

    /**
     * 执行文件上传策略
     * @param fileUploadMode
     * @param file
     * @param suffix
     * @return
     */
    public String executeFileUploadStrategy(String fileUploadMode, MultipartFile file, String suffix) {
        return fileUploadStrategyMap.get(fileUploadMode).fileUpload(file, suffix);
    }


    public Boolean executeFileDeleteStrategy(String fileUploadMode, String... fileNames) {
        return fileUploadStrategyMap.get(fileUploadMode).deleteFile(fileNames);
    }


    public List<String> executeFileInfoStrategy(String strategy) {
        return fileUploadStrategyMap.get(strategy).getAllImages();
    }
}
